package com.ciwong.epaper.widget;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;

import com.ciwong.epaper.util.LogOutUtil;
import com.ciwong.mobilelib.widget.CWDialog;

/**
 * Created by Administrator on 2018/3/15.
 */

public class NewLoginDialog  {
    private Context mContext;
    private CWDialog   dialogloin;
    private DialogInterface.OnClickListener mOnClickListener;

    public NewLoginDialog(Context context) {
       this.mContext=context;
        init();
    }

    private void init() {
        try{
            dialogloin=new CWDialog(((Activity) mContext));
            dialogloin.setMessage("你现在是游客账号,需登录后才可使用该功能。");
            dialogloin.setPositiveButton("马上登录", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if(mOnClickListener!=null){
                        mOnClickListener.onClick(dialogloin,DialogInterface.BUTTON_POSITIVE);
                    }
                    dialogloin.dismiss();
                    LogOutUtil.logOut((Activity) mContext);
                }
            });

            dialogloin.setNegativeButton("暂不登录", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    if(mOnClickListener!=null){
                        mOnClickListener.onClick(dialogloin,DialogInterface.BUTTON_NEGATIVE);
                    }
                    dialogloin.dismiss();
                }
            });
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public void showLoginDialog(){
        try {
            if(dialogloin!=null){
                dialogloin.show();
            }
        }catch (Exception e){
            e.getStackTrace();
        }

    }

    public void setNewLoginOnClickListener(DialogInterface.OnClickListener onClickListener){
        mOnClickListener = onClickListener;
    }
}
